$(function () {
    //购物车 ---------------------------------------
    $('.nav .nav-content .nav-content-right .shopping').on({
        mouseenter: function () {
            $(this).css('backgroundColor', 'white')
            $(this).children('a').css('color', 'orangered')
            //使用stop防止鬼畜
            $('.nav .nav-content .nav-content-right .shopslide').stop().slideDown(300);
        },
        mouseleave: function () {
            $(this).css('backgroundColor', 'rgb(66,66,66)')
            $(this).children('a').css('color', 'rgb(190, 185, 185)')
            $('.nav .nav-content .nav-content-right .shopslide').stop().slideUp(300);
        }
    })
    //购物车 ---------------------------------------

    //搜索框 ------------------------------------------
    $('.nav2 .nav2-search input').on({
        focus: function () {
            // console.log(666);
            $('.nav2 .nav2-search input,.nav2 .nav2-search span').css({
                borderColor: 'orangered'
            })
            $('.nav2 .nav2-search ul').show()
        },
        blur: function () {
            // console.log(777);
            $('.nav2 .nav2-search input,.nav2 .nav2-search span').css({
                borderColor: 'grey'
            })
            $('.nav2 .nav2-search ul').hide()
        }
    })
    //搜索框 ------------------------------------------

    //导航栏隐藏部分-------------------------------------
    $('.nav2 .nav2-center').on({
        mouseenter: function () {
            // console.log(666);
            $('.nav2 .nav2-center .nav2-center-shadow').stop().slideDown(200);
        },
        mouseleave: function () {
            $('.nav2 .nav2-center .nav2-center-shadow').stop().slideUp(200);
        }
    })


    //导航栏隐藏部分-------------------------------------


    //轮播图 ----------------------------------
    //轮播图隐藏部分
    $('.body-movePicture .body-movePicture-left').on({
        mouseenter: function () {
            $('.body-movePicture .body-movePicture-left .body-movePicture-left-shadow').show();
        },
        mouseleave: function () {
            $('.body-movePicture .body-movePicture-left .body-movePicture-left-shadow').hide();
        }
    })

    //动态设置小圆圈
    $('.body-movePicture-right ul li').each((index, domEle) => {
        // console.log(index);
        // console.log(domEle);
        var li = $('<li></li>');
        $('.body-movePicture-right ol').append(li);
    })
    //设置鼠标移动事件
    $('.body-movePicture-right').on({
        mouseover: function () {
            clearInterval(timer)
        },
        mouseout: function () {
            timer = setInterval(function () {
                num++;
                if (num == 5) {
                    num = 0;
                }
                $('.body-movePicture-right ol li').eq(num).addClass('current').siblings().removeClass('current');
                $('.body-movePicture-right ul li:eq(' + num + ')').fadeIn(function () {
                    flag = true
                }).siblings().fadeOut();
            }, 2000)
        }
    })
    var num = 0;
    $('.body-movePicture-right ul li:eq(' + num + ')').fadeIn().siblings().fadeOut()
    $('.body-movePicture-right ol li').eq(num).addClass('current').siblings().removeClass('current');
    //设置节流阀 防止点击过快变乱 
    var flag = true;
    //左箭头控制翻页
    $('.body-movePicture-right-left').on('click', function () {
        if (flag) {
            flag = false;
            num--;
            if (num < 0) {
                num = 4;
            }
            // console.log(num);
            $('.body-movePicture-right ol li').eq(num).addClass('current').siblings().removeClass('current');
            $('.body-movePicture-right ul li:eq(' + num + ')').fadeIn(function () {
                flag = true
            }).siblings().fadeOut();
        }
    })
    //右箭头控制翻页
    $('.body-movePicture-right-right').on('click', function () {
        if (flag) {
            flag = false;
            num++;
            if (num > 4) {
                num = 0;
            }
            // console.log(num);
            $('.body-movePicture-right ol li').eq(num).addClass('current').siblings().removeClass('current');
            $('.body-movePicture-right ul li:eq(' + num + ')').fadeIn(function () {
                flag = true
            }).siblings().fadeOut();
        }
    })

    //点击小圆圈控制图片
    $('.body-movePicture-right-circle li').on('click', function () {
        // console.log($(this).index());
        num = $(this).index();
        $('.body-movePicture-right ol li').eq(num).addClass('current').siblings().removeClass('current');
        $('.body-movePicture-right ul li:eq(' + num + ')').fadeIn(function () {
            flag = true
        }).siblings().fadeOut();
    })

    //定时器自动播放图片
    var timer = setInterval(function () {
        num++;
        if (num == 5) {
            num = 0;
        }
        $('.body-movePicture-right ol li').eq(num).addClass('current').siblings().removeClass('current');
        $('.body-movePicture-right ul li:eq(' + num + ')').fadeIn(function () {
            flag = true
        }).siblings().fadeOut();
    }, 2000)
    //轮播图 ----------------------------------------

    //侧边栏 ----------------------------------------
    $(window).on('scroll', function () {
        // console.log($(document).scrollTop());
        if ($(document).scrollTop() >= 1050) {
            $('.aside ul li:last-child').show()
        } else {
            $('.aside ul li:last-child').hide()
        }
    })
    //点击回到顶部事件
    $('.aside ul li:last-child').on('click', function () {
        $('html').animate({
            scrollTop: 0
        }, 500)
    })
    $('.aside ul li:first-child').on({
        mouseenter: function () {
            $('.aside .aside-shadow').show()
        },
        mouseleave: function () {
            $('.aside .aside-shadow').hide()
        }
    })
    //侧边栏 ----------------------------------------

    //倒计时 ----------------------------------------
    var setTime = setInterval(function () {
        var time1 = +new Date();
        var time2 = +new Date('2020-8-14 10:00:00');
        var time3 = (time2 - time1) / 1000;
        // console.log(time3);
        var hour = parseInt(time3 / 60 / 60);
        if (hour < 10) {
            hour = '0' + hour;
        }
        var minute = parseInt(time3 / 60 % 60);
        if (minute < 10) {
            minute = '0' + minute;
        }
        // console.log(minute);
        var second = parseInt(time3 % 60);
        if (second < 10) {
            second = '0' + second;
        }
        // div.children[0].innerHTML = hour;
        // div.children[2].innerHTML = minute;
        // div.children[4].innerHTML = second;
        $('.setTime ul li').eq(0).html(hour);
        $('.setTime ul li').eq(2).html(minute)
        $('.setTime ul li').eq(4).html(second)
    }, 1000)
    //倒计时 ----------------------------------------

    //倒计时旁边的轮播图 ------------------------------
    var num1 = 0;
    $('.quickShop-top div button:first').on('click', function () {

        console.log(num1);
        num1--;
        if (num1 >= 0) {
            $('.quickShop-center .movePic ul').animate({
                left: -992 * num1
            }, 500)
        } else {
            num1 = 0;
        }

    })

    //右箭头控制页面
    $('.quickShop-top div button:last').on('click', function () {
        num1++;
        if (num1 < 3) {
            $('.quickShop-center .movePic ul').animate({
                left: -992 * num1
            }, 500)
        } else {
            num1 = 2;
        }

    })

    //倒计时旁边的轮播图 ------------------------------

    //家电上面样式切换 --------------------------------
    // $('.homeEle-center-two').hide()
    $('.homeEle-top-right span').on('mouseover', function () {
        // console.log($(this));
        $(this).addClass('current2').siblings().removeClass('current2')
        // console.log($(this).attr('index'));
        if ($(this).attr('index') == 1) {
            $('.homeEle-center-one').show().siblings().hide()
        } else if ($(this).attr('index') == 2) {
            $('.homeEle-center-two').css('display', 'flex').siblings().hide()
        }
    })
    //家电上面样式切换 --------------------------------




















})